-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MONGOID-5900, MONGOID-5901 - Bugfix 🐛 The combination of localized and aliased fields is broken with pluck #6044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where plucking localized and aliased fields was broken due to incorrect field name resolution. The fix ensures that database_field_name
is called after removing _translations
from field names in the pluck operation.
- Adds comprehensive test coverage for pluck operations with localized and aliased fields
- Fixes field name resolution in the pluck method by properly handling aliased localized fields
- Updates model definitions to support the new test scenarios
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
spec/support/models/seo.rb | Adds localized and aliased fields for embedded pluck testing |
spec/support/models/product.rb | Adds company association to support has_many pluck tests |
spec/support/models/passport.rb | Adds aliased localized field for embedded pluck testing |
spec/support/models/company.rb | Adds products association for has_many pluck tests |
spec/mongoid/criteria_spec.rb | Adds test cases for localized+aliased field pluck scenarios |
spec/mongoid/association/referenced/has_many/enumerable_spec.rb | Adds comprehensive pluck tests including localized+aliased scenarios |
lib/mongoid/contextual/mongo.rb | Fixes field name resolution by applying database_field_name after cleansing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
it 'returns the translation for the current locale' do | ||
I18n.with_locale(:ja) do | ||
expect(plucked).to eq('京都') | ||
end | ||
end | ||
|
||
it 'returns the translation for the current locale when unaliased' do | ||
I18n.with_locale(:ja) do | ||
expect(plucked_unaliased).to eq('京都') | ||
end | ||
end | ||
|
||
it 'returns the full _translation hash' do | ||
expect(plucked_translations).to eq({ 'en' => 'Kyoto', 'ja' => '京都' }) | ||
end | ||
|
||
it 'returns the translation for the requested locale' do | ||
expect(plucked_translations_field).to eq('Kyoto') | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test data setup doesn't match the expected values. The setup creates 'english-text'/'deutsch-text' but the tests expect 'Kyoto'/'京都'. This will cause test failures.
Copilot uses AI. Check for mistakes.
This PR adds tests for pluck cases, both of which are broken on master.
I have fixed the non-embedded case, however, I think the best fix will patch
#cleanse_localized_field_names
so that it correctly callsdatabase_field_name
after removing_translations
from the name.To test: